#!/usr/bin/perl
# Unspool.pm
# Copyright (C) 2006, 2007  Stephane Alnet
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# 

package CCNCore::Provision::Unspool;
use strict; use warnings;
use CCNCore::Provision::Base;
use base qw(CCNCore::Provision::Base);

=pod

    CCNCore::Provision::Unspool is the class symmetric to CCNCore::Provision::Distributed
    that handles an action on a host and sends a ticket-completed event back to
    the sender.

    my $self = new CCNCore::Provision::Unspool($p,$callback_pk,$ticket_id);

    $self->reply(@return)
        $callback   Server pk to notify
        $ticket     Ticket pk (see CCN::IPC::Ticket)

=cut

use CCNCore::Provision::Distributed;

sub initialize($$$)
{
    my $self = shift;
    my $ticket   = pop;
    my $callback = pop;
    $self->{callback} = $callback;
    $self->{ticket} = $ticket;
    $self->SUPER::initialize(@_);
}

sub reply
{
    my $self = shift;

    my $remote = new CCNCore::Provision::Distributed($self->p);

    # Spool a reply back using "ticket-completed".
    # The optional parameters are used as the value for the "return" context in the ticket.
    return $remote->spool_this($self->{callback},$self->{ticket},join(' ','ticket-completed',@_));
}
1;